<template>
    <div class="content">
        <template v-if="openid_origin === openid">
            <!--            *******-->
            <!--            *******-->
            <!--            *******-->
            <!--            人员基本信息-->
            <!--            *******-->
            <!--            *******-->
            <!--            *******-->
            <div>
                <div class="title">人员基本信息</div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>姓名：</span>
                    </div>
                    <div class="van-cell__value">
                        {{item.name}}
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>性别：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{item.sex}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>证件类型：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{card_type_name}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>证件号：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{cardNo}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>联系电话：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{phone}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>是否常住居民：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body" v-if="item.is_permanent === '1'">
                            是
                        </div>
                        <div class="van-field__body" v-if="item.is_permanent === '0'">
                            否
                        </div>
                    </div>
                </div>
                <!--<div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label radio-item">
                        <span>现居区域：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{item.area}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label radio-item">
                        <span>现居街道：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{item.street}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field" v-if="item.community">
                    <div class="van-cell__title van-field__label radio-item">
                        <span>现居街道：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{item.community}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label radio-item">
                        <span>具体地址：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{item.address}}
                        </div>
                    </div>
                </div>-->
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label radio-item">
                        <span>省：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{item.loc_province}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label radio-item">
                        <span>市：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{item.loc_city}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label radio-item">
                        <span>详细地址：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{item.loc_address}}
                        </div>
                    </div>
                </div>
            </div>
            <!--            *******-->
            <!--            *******-->
            <!--            *******-->
            <!--            来(返)沈情况-->
            <!--            *******-->
            <!--            *******-->
            <!--            *******-->
            <div class="tou">
                <div class="title">来(返)沈情况</div>
                <div class="div1">
                    <div class="van-cell van-field">
                        <div class="van-cell__title van-field__label">
                            <span>出发地：</span>
                        </div>
                        <div class="van-cell__value">
                            <div class="van-field__body">
                                {{item.originate_province}}{{item.originate_city}}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="van-cell van-field" v-if="item.is_permanent === '0'">
                    <div class="van-cell__title van-field__label">
                        <span>出发时间：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{this.$common.xeUtils.toDateString(item.arrive_time, 'yyyy-MM-dd')}}
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label radio-item">
                        <span>途径：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body" v-if="item.viaway">
                            {{item.viaway}}
                        </div>
                        <div class="van-field__body" v-else>
                            无
                        </div>
                    </div>
                </div>
            </div>
            <!--            *******-->
            <!--            *******-->
            <!--            *******-->
            <!--            其他信息-->
            <!--            *******-->
            <!--            *******-->
            <!--            *******-->
            <div class="other-info" v-if="item.concentration_type !== '0'">
                <div class="title">其他信息</div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>特殊人群：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body" v-if="item.concentration_type === '1'">
                            集中住宿务工人员
                        </div>
                        <div class="van-field__body" v-if="item.concentration_type === '2'">
                            集中住宿在校学生
                        </div>
                        <div class="van-field__body" v-if="item.concentration_type === '3'">
                            宾馆酒店住宿客人
                        </div>
                    </div>
                </div>
                <div class="suggest van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>名称：</span>
                    </div>
                    <div class="van-cell__value">
                        <div class="van-field__body">
                            {{item.concentration_type_remark}}
                        </div>
                    </div>
                </div>
            </div>
        </template>
        <template v-if="openid_origin !== openid">
            <div class="suggest van-cell van-field">
                <div class="van-cell__title van-field__label radio-item">
                    <span>省：</span>
                </div>
                <div class="van-cell__value">
                    <div class="van-field__body">
                        {{item.loc_province}}
                    </div>
                </div>
            </div>
            <div class="suggest van-cell van-field">
                <div class="van-cell__title van-field__label radio-item">
                    <span>市：</span>
                </div>
                <div class="van-cell__value">
                    <div class="van-field__body">
                        {{item.loc_city}}
                    </div>
                </div>
            </div>
            <div class="suggest van-cell van-field">
                <div class="van-cell__title van-field__label radio-item">
                    <span>详细地址：</span>
                </div>
                <div class="van-cell__value">
                    <div class="van-field__body">
                        {{item.loc_address}}
                    </div>
                </div>
            </div>
            <div class="van-cell van-field" v-if="item.is_permanent === '0'">
                <div class="van-cell__title van-field__label">
                    <span>出发时间：</span>
                </div>
                <div class="van-cell__value">
                    <div class="van-field__body">
                        {{this.$common.xeUtils.toDateString(item.arrive_time, 'yyyy-MM-dd')}}
                    </div>
                </div>
            </div>
        </template>
    </div>
</template>

<script>
import { getPermitByOpenIdTwo, insertUserPermitPlace } from '@/api/yi-qing-fang-kong.js'
// import { Dialog } from 'vant'
// 获取用户信息new
import { getUserLoginInfo } from '@/api/wx-api'
export default {
  data () {
    return {
      openid_origin: this.$route.query.openid,
      openid: '',
      cardNo: '',
      item: {},
      card_type_name: '',
      phone: '',
      jingdu: '123.410782',
      weidu: '41.789928'
    }
  },
  methods: {
    getLocation () {
      let isSuccess = false// 获取位置成功还是失败
      let _this = this
      if (!isSuccess) {
        this.$common.getLocation(function (option) {
          _this.jingdu = option.longitude
          _this.weidu = option.latitude
          console.log(_this.jingdu, '获取后经度')
          console.log(_this.weidu, '获取后纬度')
          // 存入信息
          const param = {
            openid: _this.openid_origin,
            longitude: _this.jingdu,
            latitude: _this.weidu
          }
          _this.insertUserPermitPlace(param)
        })
        isSuccess = true
        console.log('默认经度', this.jingdu)
        console.log('默认纬度', this.weidu)
        // setTimeout(function () {
        //   if (!isSuccess) {
        //     // 获取位置失败,手动设置
        //     Dialog.alert({
        //       message: '获取位置失败默认地址沈阳站'
        //     }).then(() => {
        //       _this.jingdu = '123.410782'
        //       _this.weidu = '41.789928'
        //     })
        //   }
        // }, 6000)
      }
    },
    getMyInfo () {
      getUserLoginInfo().then(ret => {
        console.log('用户信息页面回调', ret.data.data)
        this.openid = ret.data.data.openid
      })
    },
    init () {
      const data = { openid: this.openid_origin }
      getPermitByOpenIdTwo(data).then(ret => {
        const data = ret.data.data
        if (data) {
          this.item = data
          this.cardNo = this.item.card_no.replace(/^(.{4})(?:\d+)(.{4})$/, '$1******$2')
          this.phone = this.item.tel.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
          if (this.item.card_type === '1') {
            this.card_type_name = '身份证'
          }
          if (this.item.card_type === '2') {
            this.card_type_name = '军官证'
          }
          if (this.item.card_type === '3') {
            this.card_type_name = '护照'
          }
          if (this.item.card_type === '4') {
            this.card_type_name = '港澳通行证'
          }
          if (this.item.card_type === '5') {
            this.card_type_name = '儿童'
          }
        }
      })
    },
    insertUserPermitPlace (data) {
      insertUserPermitPlace(data).then(ret => {
        if (ret.data.errcode === 0) {
          console.log('后台存入地理位置成功')
        }
      })
    }
  },
  mounted () {
    console.log('route', this.$route)
    console.log('openid_origin', this.openid_origin)
    this.getMyInfo()
    this.init()
    this.getLocation()
  },
  watch: {
    openid (val) {
      console.log('扫的openid变化', this.openid)
    },
    openid_origin () {
      console.log('被扫openid_origin变化', this.openid_origin)
    }
  }
}
</script>

<style scoped>
    .van-radio{
        float: left;
        margin-right: 10px;
    }
    .title{
        width: 100%;
        padding: 0.625rem 0.9375rem;
        font-size: 12px;
    }
    .action-item .van-cell__title{
        -webkit-box-flex: inherit;
        -webkit-flex: inherit;
        flex: inherit;
        width: 5.625rem;
    }
    .find{
        border-radius: 25px;
        background-color: #996666;
        color: white;
        margin-top: 15px;
        height: 33px;
        line-height: 1px;
        margin-left: 2%;
        width: 96%;
    }
    .content{
        width: 100%;
        background-color: #F5F5F5;
    }
    .content >>> .van-cell{
        margin-left: 2%;
        width: 96%;
        font-size: 12px;
    }
    .content >>> .van-dialog__content{
        padding: 10px;
        text-indent: 30px;
    }
    .van-field__control{
        font-size: 12px;
    }
    .content >>> .van-cell__value .van-field__body .van-field__control{
        font-size: 12px;
    }
    .city-card-common-btn{
        color: white;
        font-size: 12px;
        padding: 10px 0;
        width: 100%;
        border-radius: 5px;
        text-align: center;
        background-color: #75ACDC;
    }
    .div-bot{
        padding: 8px;
    }
    .content >>> .van-cell__value{
        flex: inherit;
        font-size: 12px;
    }
    .van-action-sheet__cancel, .van-action-sheet__item{
        font-size: 12px;
    }
    .van-cell__value span{
        /*color: black;*/
    }
    .van-dropdown-menu {
        height: 25px;
    }
     .van-hairline--top-bottom::after {
         border-width: 0px  0px;
     }
    .chaochu >>> .van-cell__value{
       width: 100%;
    }
    .div1 >>> .van-cell__value{
        width: 100%;
    }
    .div2 >>> .van-cell__value{
        width: 100%;
    }
    .other-info .van-field__label.radio-item{
        width: 8.625rem;
    }
    .tou .van-cell__value{
        width: auto;
    }
    .suggest.van-cell.van-field span{
        width: 5rem;
    }
</style>
